<?php

include('class/pdmirs.php');
/* No output before new pdmirs()-line. 
Sets charset to UTF-8 using header() */
$p = new pdmirs();

include('config.php');

switch ($_GET['action']) {
    case 'test_testdb':
    $p->connect();
    $p->adodb_test();
    break;
    
    case 'add_testdb':
        if ($_POST['submit'] == 'Legg til melding i testtabell') {
            /* Read form data ($_POST) and add message to db using adodb-kode */
            echo "Adding message";
            $message = $_POST['message'];
            
            $p->connect();
            if ($p->add_message($message)) {
            echo $p->_("Message added sucsesfully");
            } else {
            echo $p->_("Message not added, se errors: ") . $p->dbErrorMsg();
            }
            
            
        } else {
            /* Print HTML-form for adding message-es to testtable*/
                echo <<<EndOfForm
<form action="?action=add_testdb" method="post"><br />
    <input type="text" name="message"><br />
    <input type="submit" name="submit" value="Legg til melding i testtabell">
</form>
EndOfForm;

var_dump($_POST);

        }
    break;
    
    default:
        echo 'Pdmirs says: No action defined.<br />';
        echo '<a href="?action=test_testdb">Sjekk testdatabase</a><br />';
        echo '<a href="?action=add_testdb">Legg til poster i testdatabase</a>';    
    break;
}

echo "\n\n<!-- Hade verden fra PDMIRS -->"; /* Now we died */
?>
